package cn.myjava.gupao.mode.singleton;

/**
 * 懒汉式单例 - 静态内部类
 *
 * Created by RenFu
 * Date: 2019/5/12
 */
public class LazyInnerClassSingleton {

    private LazyInnerClassSingleton(){
        // 在构造函数中添加判断，防止反射破坏单例
        if (LazyHolder.LAZY != null) {
            throw new RuntimeException("不允许创建多个实例");
        }
    }

    public static LazyInnerClassSingleton getInstance() {
        return LazyHolder.LAZY;
    }

    // 默认不加载
    private static class LazyHolder {
        private static final LazyInnerClassSingleton LAZY = new LazyInnerClassSingleton();
    }
}
